package com.changgou.web.getaway.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class AuthServiceImpl implements AuthService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public String getJtiFromCookie(ServerHttpRequest request) {
        //获取cookie中的一个cookie, cookie的名字叫做uid的
        HttpCookie httpCookie = request.getCookies().getFirst("uid");
        if (httpCookie != null) {
            return httpCookie.getValue();
        }
        return null;
    }

    @Override
    public String getJwtByJtiFromRedis(String jti) {
        Object jwtObject = redisTemplate.boundValueOps(jti).get();
        if (jwtObject != null) {
            return String.valueOf(jwtObject);
        }
        return null;
    }
}
